package com.yuan;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.yuan.service.HbcarmxService;
import com.yuan.黄鹏.Hbcarmx;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;

/*
 *  @author 雨安
 *  类名： HuangPengApplication
 *  创建时间：2024/4/18
 */
@SpringBootTest
public class HuangPengApplication extends AnalysisEventListener<Hbcarmx> {



    @Autowired
    private HbcarmxService hbcarmxService;

    @Test
    void hh(){
        //设置读取的文件地址
        String fileName = "D:\\黄鹏excel处理\\副本20240417090531250.xlsx";
        //渎职 1.文件名 2.转换实体类 3.监听对象
        ExcelReader reader = EasyExcel.read(fileName, Hbcarmx.class, new HuangPengApplication())
                //构建
                .build();
        // 读取Excel文件中的数据
        reader.read();
        // 关闭reader
        reader.finish();

        hbcarmxService.saveBatch(this.hbList);
    }

    //创建初始化默认集合数据
    private static List<Hbcarmx> hbList = new ArrayList<>();

    @Override
    public void invoke(Hbcarmx carmx, AnalysisContext analysisContext) {
        this.hbList.add(carmx);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("读取完毕。。。");
    }
}
